package com.lh.controller;

import com.lh.entity.Category;
import com.lh.entity.Result;
import com.lh.service.CategoryService;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    //新增文章类型
    @PostMapping("/addCategory")
    public Result addCategoryType(@RequestBody @Validated Category category) {
      return   categoryService.addCategoryType(category);

    }

    //获取文章类型列表
    @GetMapping("/categoryList")
    public Result<List<Category>> getAllCategoryType() {
        List<Category> categoryList=categoryService.categoryList();
        return Result.success(categoryList);
    }

    //获取文章详情
    @GetMapping("/detail")
    public Result<Category> getCategoryDetail(@RequestParam int id) {
       Category category= categoryService.getCategory(id);
        return Result.success(category);
    }

    //更新文章分类
    @PutMapping("/updateCategory")
    public Result updateCategory( @RequestBody @Validated(Category.Update.class) Category category) {
       return categoryService.updateCategory(category);
    }

    //删除文章分类
    @DeleteMapping("/deleteCategory")
    public Result deleteCategory(@RequestParam Integer id) {
        return categoryService.deleteCategory(id);
    }
}
